package com.ltkj.shop.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ltkj.common.core.utils.DateUtils;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.domain.vo.ShopPostageConfigVo;
import com.ltkj.shop.mapper.ShopPostageConfigBizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.shop.mapper.ShopPostageConfigMapper;
import com.ltkj.shop.domain.ShopPostageConfig;
import com.ltkj.shop.service.IShopPostageConfigService;

/**
 * 邮费配置Service业务层处理
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Service
public class ShopPostageConfigServiceImpl implements IShopPostageConfigService 
{
    @Autowired
    private ShopPostageConfigMapper shopPostageConfigMapper;
    @Autowired
    private ShopPostageConfigBizMapper shopPostageConfigBizMapper;

    /**
     * 查询邮费配置
     * 
     * @param id 邮费配置主键
     * @return 邮费配置
     */
    @Override
    public ShopPostageConfig selectShopPostageConfigById(Long id)
    {
        return shopPostageConfigMapper.selectShopPostageConfigById(id);
    }

    /**
     * 查询邮费配置列表
     * 
     * @param shopPostageConfig 邮费配置
     * @return 邮费配置
     */
    @Override
    public List<ShopPostageConfig> selectShopPostageConfigList(ShopPostageConfig shopPostageConfig)
    {
        return shopPostageConfigMapper.selectShopPostageConfigList(shopPostageConfig);
    }

    /**
     * 新增邮费配置
     * 
     * @param shopPostageConfig 邮费配置
     * @return 结果
     */
    @Override
    public int insertShopPostageConfig(ShopPostageConfig shopPostageConfig)
    {
        shopPostageConfig.setCreateTime(DateUtils.getNowDate());
        shopPostageConfig.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        shopPostageConfig.setIsDel("0");
        // 转换金额 元 -> 分
        shopPostageConfig.setCost(shopPostageConfig.getCost().multiply(new BigDecimal(100)));
        return shopPostageConfigMapper.insertShopPostageConfig(shopPostageConfig);
    }

    /**
     * 修改邮费配置
     * 
     * @param shopPostageConfig 邮费配置
     * @return 结果
     */
    @Override
    public int updateShopPostageConfig(ShopPostageConfig shopPostageConfig)
    {
        shopPostageConfig.setUpdateTime(DateUtils.getNowDate());
        shopPostageConfig.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        // 转换金额 元 -> 分
        shopPostageConfig.setCost(shopPostageConfig.getCost().multiply(new BigDecimal(100)));
        return shopPostageConfigMapper.updateShopPostageConfig(shopPostageConfig);
    }

    /**
     * 批量删除邮费配置
     * 
     * @param ids 需要删除的邮费配置主键
     * @return 结果
     */
    @Override
    public int deleteShopPostageConfigByIds(Long[] ids)
    {
        return shopPostageConfigBizMapper.deleteShopPostageConfigByIds(ids);
    }

    /**
     * 删除邮费配置信息
     * 
     * @param id 邮费配置主键
     * @return 结果
     */
    @Override
    public int deleteShopPostageConfigById(Long id)
    {
        return shopPostageConfigBizMapper.deleteShopPostageConfigById(id);
    }



    /**
     * 根据编码精确查询邮费配置信息
     *
     * @param shopPostageConfigVo 邮费配置查询参数
     * @return 结果
     */
    @Override
    public ShopPostageConfig selectShopPostageConfigByCode(ShopPostageConfigVo shopPostageConfigVo) {
        ShopPostageConfig config = null;
        config = shopPostageConfigBizMapper.selectByCode(shopPostageConfigVo.getCounty());
        if (null == config) {
            config = shopPostageConfigBizMapper.selectByCode(shopPostageConfigVo.getCity());
        }
        if (null == config) {
            config = shopPostageConfigBizMapper.selectByCode(shopPostageConfigVo.getProvince());
        }
        return config;
    }
}
